package com.rupertjones.globalcron.server.messaging;

import com.rupertjones.globalcron.common.messaging.ConfigurationRequest;
import org.apache.log4j.Logger;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;

/**
 * <p>&copy Rupert Jones 2013</p>
 *
 * @author rup
 */
public class MessagesFromClientsListener implements javax.jms.MessageListener {

    private static final Logger LOG = Logger.getLogger(MessagesFromClientsListener.class);

    @Override
    public void onMessage(Message message) {
        try {
            if (message instanceof ObjectMessage) {
                Object messagePayload = ((ObjectMessage) message).getObject();
                if (messagePayload instanceof ConfigurationRequest) {
                    LOG.info("Received a client configuration request from : " + ((ConfigurationRequest) messagePayload).getHostname());
                } else {
                    LOG.info("Received an unknown request from client");
                }
            }
        } catch (JMSException e) {
            LOG.error(e);
        }
    }
}
